package mvc_generator.generator;

import java.util.List;
import mvc_generator.generator.MVCGeneratorGeneratorUtils;
import mvc_generator.mVCGenerator.BooleanType;
import mvc_generator.mVCGenerator.Data;
import mvc_generator.mVCGenerator.DateType;
import mvc_generator.mVCGenerator.Declaration;
import mvc_generator.mVCGenerator.DoubleType;
import mvc_generator.mVCGenerator.IntegerType;
import mvc_generator.mVCGenerator.Model;
import mvc_generator.mVCGenerator.ModelMVC;
import mvc_generator.mVCGenerator.SimpleType;
import mvc_generator.mVCGenerator.StringType;
import org.eclipse.emf.common.util.EList;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.generator.IFileSystemAccess;
import org.eclipse.xtext.xbase.lib.Conversions;
import org.eclipse.xtext.xbase.lib.StringExtensions;

@SuppressWarnings("all")
public class ModelGenerator {
  public void doGenerate(final ModelMVC modelMVC, final List<String> databasePaths, final List<String> businessClassPaths, final List<String> daosPaths, final IFileSystemAccess fsa) {
    this.generateDatabase(modelMVC, databasePaths, fsa);
    Model _model = modelMVC.getModel();
    EList<Data> _datas = _model.getDatas();
    for (final Data data : _datas) {
      {
        this.generateDataDao(data, daosPaths, fsa);
        this.generateDataClass(data, businessClassPaths, fsa);
      }
    }
  }
  
  /**
   * @arg database: the elist of database tables that describe the database schema.
   * @arg paths the array of paths where save the file.
   * @arg fsa the file generator.
   */
  private void generateDatabase(final ModelMVC modelMVC, final List<String> databasePaths, final IFileSystemAccess fsa) {
    int i = 0;
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("CREATE DATABASE ");
    String _name = modelMVC.getName();
    _builder.append(_name, "");
    _builder.newLineIfNotEmpty();
    CharSequence fileContent = _builder;
    Model _model = modelMVC.getModel();
    EList<Data> _datas = _model.getDatas();
    for (final Data data : _datas) {
      EList<Declaration> _declarations = data.getDeclarations();
      int _length = ((Object[])Conversions.unwrapArray(_declarations, Object.class)).length;
      boolean _greaterThan = (_length > 0);
      if (_greaterThan) {
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("CREATE TABLE ");
        String _name_1 = data.getName();
        _builder_1.append(_name_1, "");
        _builder_1.append("(");
        _builder_1.newLineIfNotEmpty();
        _builder_1.append("\t");
        _builder_1.append("`id");
        String _name_2 = data.getName();
        String _firstUpper = StringExtensions.toFirstUpper(_name_2);
        _builder_1.append(_firstUpper, "	");
        _builder_1.append("` int(10) NOT NULL,");
        _builder_1.newLineIfNotEmpty();
        String _plus = (fileContent + _builder_1.toString());
        fileContent = _plus;
        EList<Declaration> _declarations_1 = data.getDeclarations();
        int _length_1 = ((Object[])Conversions.unwrapArray(_declarations_1, Object.class)).length;
        int _minus = (_length_1 - 1);
        boolean _lessThan = (i < _minus);
        boolean _while = _lessThan;
        while (_while) {
          {
            StringConcatenation _builder_2 = new StringConcatenation();
            EList<Declaration> _declarations_2 = data.getDeclarations();
            Declaration _get = _declarations_2.get(i);
            CharSequence _computeDatabaseRaw = this.computeDatabaseRaw(_get);
            _builder_2.append(_computeDatabaseRaw, "");
            _builder_2.append(" NOT NULL,");
            _builder_2.newLineIfNotEmpty();
            String _plus_1 = (fileContent + _builder_2.toString());
            fileContent = _plus_1;
            int _plus_2 = (i + 1);
            i = _plus_2;
          }
          EList<Declaration> _declarations_2 = data.getDeclarations();
          int _length_2 = ((Object[])Conversions.unwrapArray(_declarations_2, Object.class)).length;
          int _minus_1 = (_length_2 - 1);
          boolean _lessThan_1 = (i < _minus_1);
          _while = _lessThan_1;
        }
        StringConcatenation _builder_2 = new StringConcatenation();
        EList<Declaration> _declarations_2 = data.getDeclarations();
        EList<Declaration> _declarations_3 = data.getDeclarations();
        int _length_2 = ((Object[])Conversions.unwrapArray(_declarations_3, Object.class)).length;
        int _minus_1 = (_length_2 - 1);
        Declaration _get = _declarations_2.get(_minus_1);
        CharSequence _computeDatabaseRaw = this.computeDatabaseRaw(_get);
        _builder_2.append(_computeDatabaseRaw, "");
        _builder_2.append(" NOT NULL");
        _builder_2.newLineIfNotEmpty();
        String _plus_1 = (fileContent + _builder_2.toString());
        fileContent = _plus_1;
      }
    }
    StringConcatenation _builder_3 = new StringConcatenation();
    _builder_3.append(");");
    String _plus_2 = (fileContent + _builder_3.toString());
    fileContent = _plus_2;
    for (final String path : databasePaths) {
      String _name_3 = modelMVC.getName();
      String _plus_3 = (_name_3 + path);
      String _plus_4 = (_plus_3 + ".mysql");
      fsa.generateFile(_plus_4, fileContent);
    }
  }
  
  private CharSequence computeDatabaseRaw(final Declaration d) {
    CharSequence result = null;
    SimpleType _type = d.getType();
    if ((_type instanceof IntegerType)) {
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("`");
      String _name = d.getName();
      _builder.append(_name, "");
      _builder.append("` int(10)");
      result = _builder;
    } else {
      SimpleType _type_1 = d.getType();
      if ((_type_1 instanceof DoubleType)) {
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("`");
        String _name_1 = d.getName();
        _builder_1.append(_name_1, "");
        _builder_1.append("` double(10)");
        result = _builder_1;
      } else {
        SimpleType _type_2 = d.getType();
        if ((_type_2 instanceof StringType)) {
          StringConcatenation _builder_2 = new StringConcatenation();
          _builder_2.append("`");
          String _name_2 = d.getName();
          _builder_2.append(_name_2, "");
          _builder_2.append("` varchar(50)");
          result = _builder_2;
        } else {
          SimpleType _type_3 = d.getType();
          if ((_type_3 instanceof BooleanType)) {
            StringConcatenation _builder_3 = new StringConcatenation();
            _builder_3.append("`");
            String _name_3 = d.getName();
            _builder_3.append(_name_3, "");
            _builder_3.append("` boolean");
            result = _builder_3;
          } else {
            SimpleType _type_4 = d.getType();
            if ((_type_4 instanceof DateType)) {
              StringConcatenation _builder_4 = new StringConcatenation();
              _builder_4.append("date");
              result = _builder_4;
            } else {
              StringConcatenation _builder_5 = new StringConcatenation();
              _builder_5.append("@Auto_Generated: Not supported Type");
              result = _builder_5;
            }
          }
        }
      }
    }
    return result;
  }
  
  private void generateDataClass(final Data data, final List<String> businessClassPaths, final IFileSystemAccess fsa) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package ????;");
    _builder.newLine();
    _builder.newLine();
    _builder.append("import ???;");
    _builder.newLine();
    _builder.newLine();
    _builder.append("public class ");
    String _name = data.getName();
    String _firstUpper = StringExtensions.toFirstUpper(_name);
    _builder.append(_firstUpper, "");
    _builder.append(" {");
    _builder.newLineIfNotEmpty();
    {
      EList<Declaration> _declarations = data.getDeclarations();
      for(final Declaration d : _declarations) {
        _builder.append("\t");
        _builder.append("private ");
        SimpleType _type = d.getType();
        Object _generateSimpleType = this.generateSimpleType(_type);
        _builder.append(_generateSimpleType, "	");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.append("}");
    _builder.newLine();
    CharSequence result = _builder;
  }
  
  private Object generateSimpleType(final SimpleType simpleType) {
    Object _xifexpression = null;
    if ((simpleType instanceof IntegerType)) {
      _xifexpression = null;
    } else {
      Object _xifexpression_1 = null;
      if ((simpleType instanceof DoubleType)) {
        _xifexpression_1 = null;
      } else {
        Object _xifexpression_2 = null;
        if ((simpleType instanceof StringType)) {
          _xifexpression_2 = null;
        } else {
          Object _xifexpression_3 = null;
          if ((simpleType instanceof BooleanType)) {
            _xifexpression_3 = null;
          } else {
            Object _xifexpression_4 = null;
            if ((simpleType instanceof DateType)) {
              _xifexpression_4 = null;
            } else {
              _xifexpression_4 = null;
            }
            _xifexpression_3 = _xifexpression_4;
          }
          _xifexpression_2 = _xifexpression_3;
        }
        _xifexpression_1 = _xifexpression_2;
      }
      _xifexpression = _xifexpression_1;
    }
    return _xifexpression;
  }
  
  private void generateDataDao(final Data data, final List<String> daosPaths, final IFileSystemAccess fsa) {
    StringConcatenation _builder = new StringConcatenation();
    CharSequence daoContent = _builder;
    StringConcatenation _builder_1 = new StringConcatenation();
    CharSequence addContent = _builder_1;
    StringConcatenation _builder_2 = new StringConcatenation();
    CharSequence updateContent = _builder_2;
    StringConcatenation _builder_3 = new StringConcatenation();
    CharSequence deleteContent = _builder_3;
    StringConcatenation _builder_4 = new StringConcatenation();
    CharSequence getContent = _builder_4;
    StringConcatenation _builder_5 = new StringConcatenation();
    CharSequence declarationContent = _builder_5;
    StringConcatenation _builder_6 = new StringConcatenation();
    CharSequence sqlDeclarationContent = _builder_6;
    StringConcatenation _builder_7 = new StringConcatenation();
    CharSequence interrogationPointSequenceContent = _builder_7;
    StringConcatenation _builder_8 = new StringConcatenation();
    CharSequence settingPreparedStatementContent = _builder_8;
    StringConcatenation _builder_9 = new StringConcatenation();
    CharSequence idTableContent = _builder_9;
    StringConcatenation _builder_10 = new StringConcatenation();
    CharSequence settingDeleteContent = _builder_10;
    StringConcatenation _builder_11 = new StringConcatenation();
    CharSequence updateValues = _builder_11;
    StringConcatenation _builder_12 = new StringConcatenation();
    CharSequence settingUpdateContent = _builder_12;
    StringConcatenation _builder_13 = new StringConcatenation();
    CharSequence settingFieldObjectContent = _builder_13;
    boolean isFirst = true;
    int i = 0;
    StringConcatenation _builder_14 = new StringConcatenation();
    boolean _isFirst = isFirst = true;
    MVCGeneratorGeneratorUtils.toVoidExpr(Boolean.valueOf(_isFirst));
    _builder_14.newLineIfNotEmpty();
    {
      EList<Declaration> _declarations = data.getDeclarations();
      for(final Declaration declaration : _declarations) {
        {
          if (isFirst) {
            _builder_14.append("\t");
            _builder_14.append("final ");
            SimpleType _type = declaration.getType();
            String _stringRepresentation = _type.getStringRepresentation();
            _builder_14.append(_stringRepresentation, "	");
            _builder_14.append(" ");
            String _name = declaration.getName();
            _builder_14.append(_name, "	");
            boolean _isFirst_1 = isFirst = false;
            MVCGeneratorGeneratorUtils.toVoidExpr(Boolean.valueOf(_isFirst_1));
            _builder_14.newLineIfNotEmpty();
          } else {
            _builder_14.append("\t");
            _builder_14.append(", final ");
            SimpleType _type_1 = declaration.getType();
            String _stringRepresentation_1 = _type_1.getStringRepresentation();
            _builder_14.append(_stringRepresentation_1, "	");
            _builder_14.append(" ");
            String _name_1 = declaration.getName();
            _builder_14.append(_name_1, "	");
            _builder_14.newLineIfNotEmpty();
          }
        }
      }
    }
    declarationContent = _builder_14;
    StringConcatenation _builder_15 = new StringConcatenation();
    boolean _isFirst_2 = isFirst = true;
    MVCGeneratorGeneratorUtils.toVoidExpr(Boolean.valueOf(_isFirst_2));
    _builder_15.newLineIfNotEmpty();
    {
      EList<Declaration> _declarations_1 = data.getDeclarations();
      for(final Declaration declaration_1 : _declarations_1) {
        {
          if (isFirst) {
            _builder_15.append("\t");
            String _name_2 = declaration_1.getName();
            _builder_15.append(_name_2, "	");
            boolean _isFirst_3 = isFirst = false;
            MVCGeneratorGeneratorUtils.toVoidExpr(Boolean.valueOf(_isFirst_3));
            _builder_15.newLineIfNotEmpty();
          } else {
            _builder_15.append("\t");
            _builder_15.append(", ");
            String _name_3 = declaration_1.getName();
            _builder_15.append(_name_3, "	");
            _builder_15.newLineIfNotEmpty();
          }
        }
      }
    }
    sqlDeclarationContent = _builder_15;
    StringConcatenation _builder_16 = new StringConcatenation();
    boolean _isFirst_4 = isFirst = true;
    MVCGeneratorGeneratorUtils.toVoidExpr(Boolean.valueOf(_isFirst_4));
    _builder_16.newLineIfNotEmpty();
    {
      EList<Declaration> _declarations_2 = data.getDeclarations();
      for(final Declaration declaration_2 : _declarations_2) {
        {
          if (isFirst) {
            _builder_16.append("\t");
            _builder_16.append("?");
            _builder_16.newLine();
          } else {
            _builder_16.append("\t");
            _builder_16.append(", ?");
            _builder_16.newLine();
          }
        }
      }
    }
    interrogationPointSequenceContent = _builder_16;
    StringConcatenation _builder_17 = new StringConcatenation();
    int _i = i = 0;
    MVCGeneratorGeneratorUtils.toVoidExpr(Integer.valueOf(_i));
    _builder_17.newLineIfNotEmpty();
    {
      EList<Declaration> _declarations_3 = data.getDeclarations();
      for(final Declaration declaration_3 : _declarations_3) {
        _builder_17.append("lPreparedStatementCreation.setLong(");
        int _plus = (i + 1);
        int _i_1 = i = _plus;
        _builder_17.append(_i_1, "");
        _builder_17.append(", ");
        String _name_4 = declaration_3.getName();
        _builder_17.append(_name_4, "");
        _builder_17.append(");");
        _builder_17.newLineIfNotEmpty();
      }
    }
    settingPreparedStatementContent = _builder_17;
    StringConcatenation _builder_18 = new StringConcatenation();
    _builder_18.append("id");
    String _name_5 = data.getName();
    String _firstUpper = StringExtensions.toFirstUpper(_name_5);
    _builder_18.append(_firstUpper, "");
    _builder_18.newLineIfNotEmpty();
    idTableContent = _builder_18;
    StringConcatenation _builder_19 = new StringConcatenation();
    _builder_19.append("lPreparedStatementCreation.setLong(1, id");
    String _name_6 = data.getName();
    String _firstUpper_1 = StringExtensions.toFirstUpper(_name_6);
    _builder_19.append(_firstUpper_1, "");
    _builder_19.append(");");
    _builder_19.newLineIfNotEmpty();
    settingDeleteContent = _builder_19;
    StringConcatenation _builder_20 = new StringConcatenation();
    {
      EList<Declaration> _declarations_4 = data.getDeclarations();
      for(final Declaration declaration_4 : _declarations_4) {
        {
          if (isFirst) {
            String _name_7 = declaration_4.getName();
            _builder_20.append(_name_7, "");
            _builder_20.append("=?");
            _builder_20.newLineIfNotEmpty();
          } else {
            _builder_20.append(", ");
            String _name_8 = declaration_4.getName();
            _builder_20.append(_name_8, "");
            _builder_20.append("=?");
            _builder_20.newLineIfNotEmpty();
          }
        }
      }
    }
    updateValues = _builder_20;
    StringConcatenation _builder_21 = new StringConcatenation();
    _builder_21.append("lPreparedStatementCreation.setLong(");
    EList<Declaration> _declarations_5 = data.getDeclarations();
    int _length = ((Object[])Conversions.unwrapArray(_declarations_5, Object.class)).length;
    int _plus_1 = (_length + 1);
    _builder_21.append(_plus_1, "");
    _builder_21.append(", id");
    String _name_9 = data.getName();
    String _firstUpper_2 = StringExtensions.toFirstUpper(_name_9);
    _builder_21.append(_firstUpper_2, "");
    _builder_21.append(");");
    _builder_21.newLineIfNotEmpty();
    settingUpdateContent = _builder_21;
    StringConcatenation _builder_22 = new StringConcatenation();
    {
      EList<Declaration> _declarations_6 = data.getDeclarations();
      for(final Declaration declaration_5 : _declarations_6) {
        String _name_10 = data.getName();
        String _firstLower = StringExtensions.toFirstLower(_name_10);
        _builder_22.append(_firstLower, "");
        _builder_22.append(".set");
        String _name_11 = declaration_5.getName();
        String _firstUpper_3 = StringExtensions.toFirstUpper(_name_11);
        _builder_22.append(_firstUpper_3, "");
        _builder_22.append("(rs.get");
        SimpleType _type_2 = declaration_5.getType();
        String _stringRepresentation_2 = _type_2.getStringRepresentation();
        String _firstUpper_4 = StringExtensions.toFirstUpper(_stringRepresentation_2);
        _builder_22.append(_firstUpper_4, "");
        _builder_22.append("(");
        String _name_12 = declaration_5.getName();
        _builder_22.append(_name_12, "");
        _builder_22.append("));");
        _builder_22.newLineIfNotEmpty();
      }
    }
    settingFieldObjectContent = _builder_22;
    StringConcatenation _builder_23 = new StringConcatenation();
    _builder_23.append("\t");
    _builder_23.append("public String add");
    String _name_13 = data.getName();
    String _firstUpper_5 = StringExtensions.toFirstUpper(_name_13);
    _builder_23.append(_firstUpper_5, "	");
    _builder_23.append("(");
    _builder_23.append(declarationContent, "	");
    _builder_23.append(") {");
    _builder_23.newLineIfNotEmpty();
    _builder_23.append("\t");
    _builder_23.append("try {");
    _builder_23.newLine();
    _builder_23.append("\t");
    _builder_23.append("final Context lContext = new InitialContext();");
    _builder_23.newLine();
    _builder_23.append("\t");
    _builder_23.append("final DataSource lDataSource = (DataSource) lContext");
    _builder_23.newLine();
    _builder_23.append("\t");
    _builder_23.append(".lookup(RESOURCE_JDBC);");
    _builder_23.newLine();
    _builder_23.append("\t");
    _builder_23.append("final Connection lConnection = lDataSource.getConnection();");
    _builder_23.newLine();
    _builder_23.append("\t");
    _builder_23.append("// adding a new contact");
    _builder_23.newLine();
    _builder_23.append("\t");
    _builder_23.append("final PreparedStatement lPreparedStatementCreation = lConnection");
    _builder_23.newLine();
    _builder_23.append("\t");
    _builder_23.append(".prepareStatement(\"INSERT INTO ");
    String _name_14 = data.getName();
    String _upperCase = _name_14.toUpperCase();
    _builder_23.append(_upperCase, "	");
    _builder_23.append("(");
    _builder_23.append(sqlDeclarationContent, "	");
    _builder_23.append(") VALUES(");
    _builder_23.append(interrogationPointSequenceContent, "	");
    _builder_23.append(")\");");
    _builder_23.newLineIfNotEmpty();
    _builder_23.append("\t");
    _builder_23.append(settingPreparedStatementContent, "	");
    _builder_23.newLineIfNotEmpty();
    _builder_23.append("\t");
    _builder_23.append("lPreparedStatementCreation.executeUpdate();");
    _builder_23.newLine();
    _builder_23.append("\t");
    _builder_23.append("return null;");
    _builder_23.newLine();
    _builder_23.append("\t");
    _builder_23.append("} catch (NamingException e) {");
    _builder_23.newLine();
    _builder_23.append("\t");
    _builder_23.append("return \"NamingException : \" + e.getMessage();");
    _builder_23.newLine();
    _builder_23.append("\t");
    _builder_23.append("} catch (SQLException e) {");
    _builder_23.newLine();
    _builder_23.append("\t");
    _builder_23.append("return \"SQLException : \" + e.getMessage();");
    _builder_23.newLine();
    _builder_23.append("\t");
    _builder_23.append("}");
    _builder_23.newLine();
    _builder_23.append("}");
    _builder_23.newLine();
    addContent = _builder_23;
    StringConcatenation _builder_24 = new StringConcatenation();
    _builder_24.append("\t");
    _builder_24.append("public String delete");
    String _name_15 = data.getName();
    String _firstUpper_6 = StringExtensions.toFirstUpper(_name_15);
    _builder_24.append(_firstUpper_6, "	");
    _builder_24.append("(int ");
    _builder_24.append(idTableContent, "	");
    _builder_24.append(") {");
    _builder_24.newLineIfNotEmpty();
    _builder_24.append("\t");
    _builder_24.append("try {");
    _builder_24.newLine();
    _builder_24.append("\t");
    _builder_24.append("final Context lContext = new InitialContext();");
    _builder_24.newLine();
    _builder_24.append("\t");
    _builder_24.append("final DataSource lDataSource = (DataSource) lContext");
    _builder_24.newLine();
    _builder_24.append("\t");
    _builder_24.append(".lookup(RESOURCE_JDBC);");
    _builder_24.newLine();
    _builder_24.append("\t");
    _builder_24.append("final Connection lConnection = lDataSource.getConnection();");
    _builder_24.newLine();
    _builder_24.append("\t");
    _builder_24.append("// adding a new contact");
    _builder_24.newLine();
    _builder_24.append("\t");
    _builder_24.append("final PreparedStatement lPreparedStatementCreation = lConnection");
    _builder_24.newLine();
    _builder_24.append("\t");
    _builder_24.append(".prepareStatement(\"DELETE FROM ");
    String _name_16 = data.getName();
    _builder_24.append(_name_16, "	");
    _builder_24.append(" WHERE ");
    _builder_24.append(idTableContent, "	");
    _builder_24.append("=?\");");
    _builder_24.newLineIfNotEmpty();
    _builder_24.append("\t");
    _builder_24.append(settingDeleteContent, "	");
    _builder_24.newLineIfNotEmpty();
    _builder_24.append("\t");
    _builder_24.append("lPreparedStatementCreation.executeUpdate();");
    _builder_24.newLine();
    _builder_24.append("\t");
    _builder_24.append("return null;");
    _builder_24.newLine();
    _builder_24.append("\t");
    _builder_24.append("} catch (NamingException e) {");
    _builder_24.newLine();
    _builder_24.append("\t");
    _builder_24.append("return \"NamingException : \" + e.getMessage();");
    _builder_24.newLine();
    _builder_24.append("\t");
    _builder_24.append("} catch (SQLException e) {");
    _builder_24.newLine();
    _builder_24.append("\t");
    _builder_24.append("return \"SQLException : \" + e.getMessage();");
    _builder_24.newLine();
    _builder_24.append("\t");
    _builder_24.append("}");
    _builder_24.newLine();
    _builder_24.append("}");
    _builder_24.newLine();
    deleteContent = _builder_24;
    StringConcatenation _builder_25 = new StringConcatenation();
    _builder_25.append("public String update");
    String _name_17 = data.getName();
    String _firstUpper_7 = StringExtensions.toFirstUpper(_name_17);
    _builder_25.append(_firstUpper_7, "");
    _builder_25.append("(");
    _builder_25.append(declarationContent, "");
    _builder_25.append(") {");
    _builder_25.newLineIfNotEmpty();
    _builder_25.append("\t\t");
    _builder_25.append("try {");
    _builder_25.newLine();
    _builder_25.append("\t\t");
    _builder_25.append("final Context lContext = new InitialContext();");
    _builder_25.newLine();
    _builder_25.append("\t\t");
    _builder_25.append("final DataSource lDataSource = (DataSource) lContext");
    _builder_25.newLine();
    _builder_25.append("\t\t");
    _builder_25.append(".lookup(RESOURCE_JDBC);");
    _builder_25.newLine();
    _builder_25.append("\t\t");
    _builder_25.append("final Connection lConnection = lDataSource.getConnection();");
    _builder_25.newLine();
    _builder_25.append("\t\t");
    _builder_25.append("// adding a new contact");
    _builder_25.newLine();
    _builder_25.append("\t\t");
    _builder_25.append("final PreparedStatement lPreparedStatementCreation = lConnection");
    _builder_25.newLine();
    _builder_25.append("\t\t");
    _builder_25.append(".prepareStatement(\"UPDATE data.name SET ");
    _builder_25.append(updateValues, "		");
    _builder_25.append(" WHERE idTableContent= ?\");");
    _builder_25.newLineIfNotEmpty();
    _builder_25.append("\t\t");
    _builder_25.append(settingPreparedStatementContent, "		");
    _builder_25.newLineIfNotEmpty();
    _builder_25.append("\t\t");
    _builder_25.append("lPreparedStatementCreation.executeUpdate();");
    _builder_25.newLine();
    _builder_25.append("\t\t");
    _builder_25.append("return null;");
    _builder_25.newLine();
    _builder_25.append("\t\t");
    _builder_25.append("} catch (NamingException e) {");
    _builder_25.newLine();
    _builder_25.append("\t\t");
    _builder_25.append("return \"NamingException : \" + e.getMessage();");
    _builder_25.newLine();
    _builder_25.append("\t\t");
    _builder_25.append("} catch (SQLException e) {");
    _builder_25.newLine();
    _builder_25.append("\t\t");
    _builder_25.append("return \"SQLException : \" + e.getMessage();");
    _builder_25.newLine();
    _builder_25.append("\t\t");
    _builder_25.append("}");
    _builder_25.newLine();
    _builder_25.append("\t");
    _builder_25.append("}");
    _builder_25.newLine();
    updateContent = _builder_25;
    StringConcatenation _builder_26 = new StringConcatenation();
    _builder_26.append("public ");
    String _name_18 = data.getName();
    String _firstUpper_8 = StringExtensions.toFirstUpper(_name_18);
    _builder_26.append(_firstUpper_8, "");
    _builder_26.append(" get");
    String _name_19 = data.getName();
    String _firstUpper_9 = StringExtensions.toFirstUpper(_name_19);
    _builder_26.append(_firstUpper_9, "");
    _builder_26.append("(int ");
    _builder_26.append(idTableContent, "");
    _builder_26.append(") {");
    _builder_26.newLineIfNotEmpty();
    _builder_26.append("\t");
    _builder_26.append("Statement statement;");
    _builder_26.newLine();
    _builder_26.append("String query = \"SELECT * FROM ");
    String _name_20 = data.getName();
    _builder_26.append(_name_20, "");
    _builder_26.append(" WHERE ");
    _builder_26.append(idTableContent, "");
    _builder_26.append("= \" + ");
    _builder_26.append(idTableContent, "");
    _builder_26.append(";");
    _builder_26.newLineIfNotEmpty();
    _builder_26.append("ResultSet rs = null;");
    _builder_26.newLine();
    _builder_26.append("      ");
    String _name_21 = data.getName();
    String _firstUpper_10 = StringExtensions.toFirstUpper(_name_21);
    _builder_26.append(_firstUpper_10, "      ");
    _builder_26.append(" ");
    String _name_22 = data.getName();
    String _firstLower_1 = StringExtensions.toFirstLower(_name_22);
    _builder_26.append(_firstLower_1, "      ");
    _builder_26.append(" = null;");
    _builder_26.newLineIfNotEmpty();
    _builder_26.append("try {");
    _builder_26.newLine();
    _builder_26.append("\t");
    _builder_26.newLine();
    _builder_26.append("final Context lContext = new InitialContext();");
    _builder_26.newLine();
    _builder_26.append("\t\t");
    _builder_26.append("final DataSource lDataSource = (DataSource) lContext");
    _builder_26.newLine();
    _builder_26.append("\t\t");
    _builder_26.append(".lookup(RESOURCE_JDBC);");
    _builder_26.newLine();
    _builder_26.append("\t\t");
    _builder_26.append("final Connection lConnection = lDataSource.getConnection();");
    _builder_26.newLine();
    _builder_26.append("\t\t ");
    _builder_26.append("statement = lConnection.createStatement();");
    _builder_26.newLine();
    _builder_26.append("\t\t        ");
    _builder_26.append("rs = statement.executeQuery(query);");
    _builder_26.newLine();
    _builder_26.append("\t\t        ");
    _builder_26.append("if (rs.next()) {");
    _builder_26.newLine();
    _builder_26.append("\t\t            ");
    String _name_23 = data.getName();
    String _firstLower_2 = StringExtensions.toFirstLower(_name_23);
    _builder_26.append(_firstLower_2, "		            ");
    _builder_26.append(" = new  ");
    String _name_24 = data.getName();
    String _firstUpper_11 = StringExtensions.toFirstUpper(_name_24);
    _builder_26.append(_firstUpper_11, "		            ");
    _builder_26.append("();");
    _builder_26.newLineIfNotEmpty();
    _builder_26.append("\t\t            ");
    _builder_26.append(settingFieldObjectContent, "		            ");
    _builder_26.newLineIfNotEmpty();
    _builder_26.append("\t\t        ");
    _builder_26.append("}");
    _builder_26.newLine();
    _builder_26.append("\t\t ");
    _builder_26.append("} catch (NamingException e) {");
    _builder_26.newLine();
    _builder_26.append("\t\t \t");
    _builder_26.append("e.printStackTrace();  ");
    _builder_26.newLine();
    _builder_26.append("\t\t");
    _builder_26.append("} catch (SQLException e) {");
    _builder_26.newLine();
    _builder_26.append("\t\t\t");
    _builder_26.append("e.printStackTrace();  ");
    _builder_26.newLine();
    _builder_26.append("\t\t");
    _builder_26.append("}");
    _builder_26.newLine();
    _builder_26.append("\t\t    ");
    _builder_26.append("return ");
    String _name_25 = data.getName();
    String _firstLower_3 = StringExtensions.toFirstLower(_name_25);
    _builder_26.append(_firstLower_3, "		    ");
    _builder_26.append(";");
    _builder_26.newLineIfNotEmpty();
    _builder_26.append("\t\t");
    _builder_26.append("}");
    _builder_26.newLine();
    getContent = _builder_26;
    StringConcatenation _builder_27 = new StringConcatenation();
    _builder_27.append("\t\t");
    _builder_27.append("package domain;");
    _builder_27.newLine();
    _builder_27.newLine();
    _builder_27.append("import java.sql.Connection;");
    _builder_27.newLine();
    _builder_27.append("import java.sql.PreparedStatement;");
    _builder_27.newLine();
    _builder_27.append("import java.sql.ResultSet;");
    _builder_27.newLine();
    _builder_27.append("import java.sql.SQLException;");
    _builder_27.newLine();
    _builder_27.newLine();
    _builder_27.append("import javax.naming.Context;");
    _builder_27.newLine();
    _builder_27.append("import javax.naming.InitialContext;");
    _builder_27.newLine();
    _builder_27.append("import javax.naming.NamingException;");
    _builder_27.newLine();
    _builder_27.append("import javax.sql.DataSource;");
    _builder_27.newLine();
    _builder_27.newLine();
    _builder_27.append("public class DAO");
    String _name_26 = data.getName();
    String _firstUpper_12 = StringExtensions.toFirstUpper(_name_26);
    _builder_27.append(_firstUpper_12, "");
    _builder_27.append(" {");
    _builder_27.newLineIfNotEmpty();
    _builder_27.append("\t");
    _builder_27.append("private final static String RESOURCE_JDBC = \"java:comp/env/jdbc/dsMyDB\";");
    _builder_27.newLine();
    _builder_27.append("\t");
    _builder_27.append(addContent, "	");
    _builder_27.newLineIfNotEmpty();
    _builder_27.append("\t");
    _builder_27.append(deleteContent, "	");
    _builder_27.newLineIfNotEmpty();
    _builder_27.append("\t");
    _builder_27.append(updateContent, "	");
    _builder_27.newLineIfNotEmpty();
    _builder_27.append("\t");
    _builder_27.append(getContent, "	");
    _builder_27.newLineIfNotEmpty();
    _builder_27.append("}");
    _builder_27.newLine();
    daoContent = _builder_27;
    for (final String path : daosPaths) {
      String _name_27 = data.getName();
      String _firstUpper_13 = StringExtensions.toFirstUpper(_name_27);
      String _plus_2 = ("DAO" + _firstUpper_13);
      fsa.generateFile(path, _plus_2);
    }
  }
}
